package com.atguigu.staservice.schedule;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService staService;

    //七子表达式（七域表达式）——>springboot：六位
    //0/5 * * * * ?：表示每个5秒执行一次这个方法
    //@Scheduled(cron = "0/5 * * * * ?")
    public void task1() {
        System.out.println("##########");
        System.out.println(new Date());
        System.out.println("定时任务task1执行了");
        System.out.println("##########");
    }

    //在每天凌晨一点，执行方法，查询前一天的数据并进行添加
    //@Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1), DateUtil.dateFormat1);
        staService.registerCount(day);
    }

}
